Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The exit-hook npm package allows developers to easily register callbacks to be executed when a Node.js process exits. This can be particularly useful for cleaning up resources, saving state, or performing other shutdown tasks in a Node.js application.
Registering a simple exit hook
This feature allows you to register a callback function that will be called when the process exits. The code sample demonstrates how to register a simple exit hook that logs a message to the console when the process exits.
const exitHook = require('exit-hook');
exitHook(() => {
console.log('Process is exiting');
});
Unregistering an exit hook
This feature allows for the deregistration of an exit hook. The code sample shows how to register an exit hook and then later unregister it, preventing the callback from being called when the process exits.
const exitHook = require('exit-hook');
const unsubscribe = exitHook(() => {
console.log('Process is exiting');
});
// Later in the code, to unregister the hook
disconnect();
signal-exit is a package that provides similar functionality to exit-hook, allowing you to run callbacks when a process exits. It differs in its implementation details and the breadth of exit signals it can handle, making it a good alternative depending on specific project requirements.
async-exit-hook extends the basic idea of exit-hook by adding support for asynchronous shutdown tasks. This can be particularly useful for ensuring that all asynchronous operations (e.g., database connections, file writes) are completed before the process exits.
Run some code when the process exits
The process.on('exit')
event doesn't catch all the ways a process can exit.
Useful for cleaning up.
$ npm install --save exit-hook
var exitHook = require('exit-hook');
exitHook(function () {
console.log('exiting');
});
// you can add multiple hooks, even across files
exitHook(function () {
console.log('exiting 2');
});
throw new Error('unicorns');
//=> exiting
//=> exiting 2
MIT © Sindre Sorhus
FAQs
Run some code when the process exits
The npm package exit-hook receives a total of 850,830 weekly downloads. As such, exit-hook popularity was classified as popular.
We found that exit-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.